import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";

var _dec, _dec2, _dec3, _dec4, _class, _class2;

/**
 * DynamicPage.js
 * @date 2018/11/7
 */
import React from 'react';
import { Button, Form } from 'antd';
import intl from 'utils/intl';
import { Bind } from 'lodash-decorators';
import PageScriptModal from "../ScriptEdit/PageScriptModal";
import styles from "../../index.less?modules";
var DynamicPage = (_dec = Form.create({
  fieldNameProp: null
}), _dec2 = Bind(), _dec3 = Bind(), _dec4 = Bind(), _dec(_class = (_class2 = /*#__PURE__*/function (_React$Component) {
  _inherits(DynamicPage, _React$Component);

  var _super = _createSuper(DynamicPage);

  function DynamicPage() {
    var _this;

    _classCallCheck(this, DynamicPage);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));
    _this.state = {
      // 页面方法的编辑
      pageScriptModalProps: {
        visible: false
      }
    };
    return _this;
  }

  _createClass(DynamicPage, [{
    key: "render",
    value: function render() {
      var _this$props$config = this.props.config,
          config = _this$props$config === void 0 ? {} : _this$props$config;
      var pageScriptModalProps = this.state.pageScriptModalProps;
      return /*#__PURE__*/React.createElement(Form, null, /*#__PURE__*/React.createElement(Form.Item, {
        className: "ant-form-item-without-help"
      }, intl.get('cpfm.ui.model.page.pageCode').d('页面编码'), ": ", config.pageCode), /*#__PURE__*/React.createElement(Form.Item, {
        className: "ant-form-item-without-help"
      }, intl.get('cpfm.ui.model.page.description').d('页面描述'), ": ", config.description), /*#__PURE__*/React.createElement(Form.Item, {
        className: "ant-form-item-without-help"
      }, /*#__PURE__*/React.createElement(Button, {
        type: "primary",
        onClick: this.handleEditPageFunc,
        className: styles['full-width']
      }, intl.get('cpfm.ui.model.page.edit').d('编辑页面方法'))), /*#__PURE__*/React.createElement(PageScriptModal, Object.assign({}, pageScriptModalProps, {
        onOk: this.handleEditPageScriptSave,
        onCancel: this.handleEditPageFuncCancel
      })));
    }
  }, {
    key: "handleEditPageScriptSave",
    value: function handleEditPageScriptSave(scripts) {
      var _this$props = this.props,
          onUpdateConfig = _this$props.onUpdateConfig,
          _this$props$config2 = _this$props.config,
          config = _this$props$config2 === void 0 ? {} : _this$props$config2;

      if (_isFunction(onUpdateConfig)) {
        onUpdateConfig(_objectSpread(_objectSpread({}, config), {}, {
          scripts: scripts
        }));
      }

      this.setState({
        pageScriptModalProps: {
          visible: false
        }
      });
    }
  }, {
    key: "handleEditPageFuncCancel",
    value: function handleEditPageFuncCancel() {
      this.setState({
        pageScriptModalProps: {
          visible: false
        }
      });
    }
  }, {
    key: "handleEditPageFunc",
    value: function handleEditPageFunc() {
      var _this$props$config3 = this.props.config,
          config = _this$props$config3 === void 0 ? {} : _this$props$config3;
      var _config$scripts = config.scripts,
          scripts = _config$scripts === void 0 ? [] : _config$scripts; // Page

      this.setState({
        pageScriptModalProps: {
          visible: true,
          dataSource: scripts
        }
      });
    }
  }]);

  return DynamicPage;
}(React.Component), (_applyDecoratedDescriptor(_class2.prototype, "handleEditPageScriptSave", [_dec2], Object.getOwnPropertyDescriptor(_class2.prototype, "handleEditPageScriptSave"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleEditPageFuncCancel", [_dec3], Object.getOwnPropertyDescriptor(_class2.prototype, "handleEditPageFuncCancel"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "handleEditPageFunc", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "handleEditPageFunc"), _class2.prototype)), _class2)) || _class);
export { DynamicPage as default };